package com.monitor.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.monitor.utils.SnowflakeIdWorker;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 新增和更新的基础数据填充.
 *
 * @author Li Zhiyuan
 * @since 2020-11-13
 */
@Component
public class MetaHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("id", SnowflakeIdWorker.getId(), metaObject);
        this.setFieldValByName("createTime", new Date(), metaObject);
        this.setFieldValByName("updateTime", new Date(), metaObject);
        this.setFieldValByName("isDelete", false, metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("createTime", new Date(), metaObject);
    }
}
